package com.lxmes.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lxmes.common.annotation.Log;
import com.lxmes.common.core.controller.BaseController;
import com.lxmes.common.core.domain.AjaxResult;
import com.lxmes.common.enums.BusinessType;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.lxmes.business.domain.CcChukuInfoPlan;
import com.lxmes.business.service.ICcChukuInfoPlanService;
import com.lxmes.common.utils.poi.ExcelUtil;
import com.lxmes.common.core.page.TableDataInfo;

/**
 * 出库计划Controller
 *
 * @author lx
 * @date 2023-06-28
 */
@Api(tags = "出库计划")
@RestController
@RequestMapping("/business/CcChukuInfoPlan")
public class CcChukuInfoPlanController extends BaseController
{
    @Autowired
    private ICcChukuInfoPlanService ccChukuInfoPlanService;

    /**
     * 查询出库计划列表
     */
    @ApiOperation("查询出库计划列表")
    @PreAuthorize("@ss.hasPermi('business:CcChukuInfoPlan:list')")
    @GetMapping("/list")
    public TableDataInfo list(CcChukuInfoPlan ccChukuInfoPlan)
    {
        startPage();
        List<CcChukuInfoPlan> list = ccChukuInfoPlanService.selectCcChukuInfoPlanList(ccChukuInfoPlan);
        return getDataTable(list);
    }

    /**
     * 导出出库计划列表
     */
    @ApiOperation("导出出库计划列表")
    @PreAuthorize("@ss.hasPermi('business:CcChukuInfoPlan:export')")
    @Log(title = "出库计划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CcChukuInfoPlan ccChukuInfoPlan)
    {
        List<CcChukuInfoPlan> list = ccChukuInfoPlanService.selectCcChukuInfoPlanList(ccChukuInfoPlan);
        ExcelUtil<CcChukuInfoPlan> util = new ExcelUtil<CcChukuInfoPlan>(CcChukuInfoPlan.class);
        util.exportExcel(response, list, "出库计划数据");
    }

    /**
     * 获取出库计划详细信息
     */
    @ApiOperation("获取出库计划详细信息")
    @PreAuthorize("@ss.hasPermi('business:CcChukuInfoPlan:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(ccChukuInfoPlanService.selectCcChukuInfoPlanById(id));
    }

    /**
     * 新增出库计划
     */
    @ApiOperation("新增出库计划")
    @PreAuthorize("@ss.hasPermi('business:CcChukuInfoPlan:add')")
    @Log(title = "出库计划", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CcChukuInfoPlan ccChukuInfoPlan)
    {
        return toAjax(ccChukuInfoPlanService.insertCcChukuInfoPlan(ccChukuInfoPlan));
    }

    /**
     * 修改出库计划
     */
    @ApiOperation("修改出库计划")
    @PreAuthorize("@ss.hasPermi('business:CcChukuInfoPlan:edit')")
    @Log(title = "出库计划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CcChukuInfoPlan ccChukuInfoPlan)
    {
        return toAjax(ccChukuInfoPlanService.updateCcChukuInfoPlan(ccChukuInfoPlan));
    }

    /**
     * 删除出库计划
     */
    @ApiOperation("删除出库计划")
    @PreAuthorize("@ss.hasPermi('business:CcChukuInfoPlan:remove')")
    @Log(title = "出库计划", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ccChukuInfoPlanService.deleteCcChukuInfoPlanByIds(ids));
    }
    @ApiOperation("生成出库单")
    @PreAuthorize("@ss.hasPermi('business:CcChukuInfoPlan:remove')")
    @Log(title = "生成出库单")
	@DeleteMapping("/handleUp/{ids}")
    public AjaxResult handleUp(@PathVariable Long[] ids)
    {
        return toAjax(ccChukuInfoPlanService.scChukuDan(ids));
    }
    /**
     * 导入出库计划
     */
    @Log(title = "出库计划", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<CcChukuInfoPlan> util = new ExcelUtil<>(CcChukuInfoPlan.class);
        List<CcChukuInfoPlan> ccChukuInfoPlanList = util.importExcel(file.getInputStream());
        String operName = getUsername();
        String message = ccChukuInfoPlanService.imporIteminfo(ccChukuInfoPlanList, updateSupport, operName);
        return AjaxResult.success(message);
    }
    // 下载模板
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) throws IOException
    {
        ExcelUtil<CcChukuInfoPlan> util = new ExcelUtil<>(CcChukuInfoPlan.class);
        util.importTemplateExcel(response,"出库计划");
    }
}
